package com.ds.admin.console.controller;

import com.ds.admin.console.param.SysUserParam;
import com.ds.admin.console.service.SysUserService;
import com.ds.admin.console.vo.SysUserVo;
import com.ds.common.web.request.PageParam;
import com.ds.common.web.response.PageInfo;
import com.ds.common.web.response.Result;
import jakarta.validation.Valid;
import jakarta.validation.Validator;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 用户信息表控制器
 *
 * @author fusheng
 * @since 2024-09-10
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/sysUser")
public class SysUserController {

    private final SysUserService sysUserService;

    /**
     * 新增
     *
     * @param param 参数
     * @return 用户ID
     */
    @PostMapping("/insert")
    public Result<String> insert(@Validated @RequestBody SysUserParam param) {
        return Result.success(sysUserService.insert(param));
    }

    /**
     * 修改
     *
     * @param param 参数
     * @return 用户ID
     */
    @PostMapping("/update")
    public Result<Long> update(@Validated @RequestBody SysUserParam param) {
        return Result.success(sysUserService.update(param));
    }

    /**
     * 删除
     *
     * @param id 用户ID
     * @return 用户ID
     */
    @GetMapping("/delete/{id}")
    public Result<Long> delete(@PathVariable Long id) {
        return Result.success(sysUserService.delete(id));
    }

    /**
     * 单个查询
     *
     * @param id 用户ID
     * @return 返回值
     */
    @GetMapping("/select/{id}")
    public Result<SysUserVo> select(@PathVariable Long id) {
        return Result.success(sysUserService.select(id));
    }

    /**
     * 列表查询
     *
     * @param param 参数
     * @return 返回值
     */
    @PostMapping("/list")
    public Result<PageInfo<SysUserVo>> list(@RequestBody PageParam<SysUserParam> param) {
        return Result.success(sysUserService.selectPage(param));
    }

}
